#include "stack.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void testStackString();
void testStackInt();

int main(){
	testStackString();
	return 0;
}

void freeString(void *elems){
	char *s = *(char**)elems;
	free(s);
}

void testStackString(){
	stack s;
	const char* letter[] = {"liuhui","mylove","hah"};
	stackNew(&s,sizeof(char*),freeString);
	for(int i=0;i<3;i++){
		char *string = strdup(letter[i]);
		stackPush(&s,&string);
	}
	for(int i=0;i<1;i++)
	{
		char *string;
		stackPop(&s,&string);
		printf("%s\n",string);
	}
	stackDispose(&s);
}

void testStackInt(){
	stack s;
	stackNew(&s,sizeof(int),NULL);
	for(int i=0;i<100;i++){
		int *x = (int*)malloc(sizeof(int));	
		*x = i;
		stackPush(&s,x);
	}
	for(int i=0;i<100;i++){
		int *elemAddr = malloc(sizeof(int));
		stackPop(&s,elemAddr);
		printf("%d,\n",*elemAddr);
		if(elemAddr != NULL){	
			free(elemAddr);
		}
	}
	stackDispose(&s);
}
